package com.tool_stdy.others;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

/**
 * Created by yan_li on 2016/1/8.
 */
public class TestMap {

    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        CompareValue cvm = new CompareValue(map);
        TreeMap Treemap = new TreeMap(cvm);
        map.put("b", 1);
        map.put("a", 3);
        map.put("c", 1);
        Treemap.putAll(map);
        System.out.println(Treemap);
    }

}

class CompareValue implements Comparator<String> {
    private HashMap<String, Integer> maps;

    public CompareValue(HashMap<String, Integer> maps) {
        this.maps = maps;
    }


    @Override
    public int compare(String o1, String o2) {
        return maps.get(o1) > maps.get(o2)?-1:1;
    }
}